package com.example.project;

import org.junit.Test;
import static org.junit.Assert.*;

/**
 * MathUtils类的单元测试
 */
public class MathUtilsTest {

    private MathUtils mathUtils = new MathUtils();

    @Test
    public void testCalculateSum() {
        int[] numbers = {1, 2, 3, 4, 5};
        assertEquals(15, mathUtils.calculateSum(numbers));
    }

    @Test
    public void testCalculateSumWithEmptyArray() {
        int[] emptyArray = {};
        assertEquals(0, mathUtils.calculateSum(emptyArray));
    }

    @Test
    public void testCalculateSumWithNull() {
        assertEquals(0, mathUtils.calculateSum(null));
    }

    @Test
    public void testCalculateAverage() {
        int[] numbers = {10, 20, 30, 40, 50};
        assertEquals(30.0, mathUtils.calculateAverage(numbers), 0.001);
    }

    @Test
    public void testFindMax() {
        int[] numbers = {5, 3, 8, 1, 9};
        assertEquals(9, mathUtils.findMax(numbers));
    }

    @Test
    public void testFindMin() {
        int[] numbers = {5, 3, 8, 1, 9};
        assertEquals(1, mathUtils.findMin(numbers));
    }

    @Test
    public void testFindMaxWithEmptyArray() {
        int[] emptyArray = {};
        assertEquals(Integer.MIN_VALUE, mathUtils.findMax(emptyArray));
    }

    @Test
    public void testFindMinWithEmptyArray() {
        int[] emptyArray = {};
        assertEquals(Integer.MAX_VALUE, mathUtils.findMin(emptyArray));
    }
}